<?php
/**
 * 小说分类Dao
 */

class Dao_NovelChargeModel extends Dao_BaseModel {

    protected $_table = 'novel_charge';

    const NORMAL_STATUS = 1;
    const REDIS_KEYWORD = 'NOVEL_CHARGE_KEY_';
    const EXTIME        = '86400';

    public function __construct ()
    {
        parent::__construct ();
    }
    
    /**
     * 根据分类id获取分类信息
     */
    public function getByNovelId ($wheres = [])
    {
        $where   = array ();
        $where[] = array ( 'novel_id' , $wheres['novel_id']);
        $info = parent::getOne( array ( 'novel_id' , 'charge_model' , 'charge_start_chapter' , 'charge_price' ) , $where );
        return $info;
    }
    
    /**
     * 获取收费高的小说
     */
    public function getHighCostNovel( $offset = 0 , $pageSize = 10 , $ids = [] )
    {
        $where      = "";
        if( !empty( $ids ) ){
            $where  = " AND `novel_id` NOT IN (" . implode( "," , $ids ) .")";
        }
        $sql = "SELECT distinct(novel_id) FROM xs_novel_charge "
                . "WHERE `charge_model` != 0 "
                . $where
                . "ORDER BY `charge_price` DESC, `novel_update_time` DESC "
                . "LIMIT $offset , $pageSize;";
        $info['list'] = $this->query($sql);
        
        return $info;
    }
    
    public function getHighCostNovelCount( $ids = [] )
    {
        $where      = "";
        if( !empty( $ids ) ){
            $where  = " AND `novel_id` NOT IN (" . implode( "," , $ids ) .")";
        }
        $count_sql = "SELECT count(distinct(novel_id)) as cnt FROM xs_novel_charge "
                . $where
                . "WHERE `charge_model` != 0 ";
        $count = $this->query($count_sql);
        return $count[0]['cnt'];
    }

    
}
